import 'package:appflutterhomeschool/provider/provider_widget.dart';
import 'package:appflutterhomeschool/res/colors.dart';
import 'package:appflutterhomeschool/res/styles.dart';
import 'package:appflutterhomeschool/ui/widgets/button_widget.dart';
import 'package:appflutterhomeschool/ui/widgets/widgets.dart';
import 'package:appflutterhomeschool/view_model/my/change_password_view_model.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

///用户： ninetailedfox
///时间： 2020/6/27
///邮箱： 1037438704@qq.com
///功能： 修改密码页面
class ChangePasswordPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ProviderWidget<ChangePasswordViewModel>(
      model: ChangePasswordViewModel(context),
      onModelReady: (value) => value.initView(),
      builder: (context, viewModel, child) {
        return GestureDetector(
          onTap: () => FocusScope.of(context).requestFocus(FocusNode()),
          child: Scaffold(
            resizeToAvoidBottomInset: false,
            backgroundColor: Colors.white,
            appBar: AppBar(
              brightness: Brightness.light,
              elevation: 0,
              leading: IconButton(
                icon: Icon(Icons.clear, color: Colors.black),
                onPressed: () => Navigator.pop(context),
              ),
            ),
            body: Container(
              padding: EdgeInsets.only(
                  left: ScreenUtil().setWidth(125),
                  right: ScreenUtil().setWidth(125)),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  Container(
                      alignment: Alignment.center,
                      child: Text("修改密码", style: TextStyles.textDark70)),
                  SizedBox(height: ScreenUtil().setWidth(100)),
                  TextFieldWidget(
                    hintText: "请输入原密码",
                    textEditingController: viewModel.oldPassword,
                    obscureText: viewModel.obscure1Text,
                    iconEye: GestureDetector(
                      child: Icon(
                        viewModel.obscure1Text
                            ? Icons.visibility_off
                            : Icons.remove_red_eye,
                        color: Colours.text_dark,
                        size: ScreenUtil().setSp(62),
                      ),
                      onTap: () => viewModel.initEvent(0),
                    ),
                    valueChanged: (value) {
                      viewModel.passwordText = value;
                    },
                  ),
                  TextFieldWidget(
                    textEditingController: viewModel.newPassword,
                    hintText: "请输入新密码",
                    obscureText: viewModel.obscure2Text,
                    iconEye: GestureDetector(
                      child: Icon(
                        viewModel.obscure2Text
                            ? Icons.visibility_off
                            : Icons.remove_red_eye,
                        color: Colours.text_dark,
                        size: ScreenUtil().setSp(62),
                      ),
                      onTap: () => viewModel.initEvent(1),
                    ),
                    valueChanged: (value) {
                      viewModel.passwordText = value;
                    },
                  ),
                  SizedBox(height: ScreenUtil().setSp(80)),
                  SureMaterialButton(
                    buttonName: "修改密码",
                    onPressed: () =>viewModel.initEvent(2),
                  ),
                  SizedBox(height: ScreenUtil().setSp(43)),
                ],
              ),
            ),
          ),
        );
      },
    );
  }
}
